/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.skyeye.modeling.customerized.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.skyeye.modeling.customerized.model.SimpleOutput;

/**
 * @author danlee
 */
public class GroundFigure extends OutputFigure {

	private static final Dimension SIZE = new Dimension(50, 50);

	/**
	 * Constructor for GroundFigure.
	 */
	public GroundFigure() {
		super();
	}

	/**
	 * @see org.eclipse.draw2d.Figure#getPreferredSize(int, int)
	 */
	public Dimension getPreferredSize(int wHint, int hHint) {
		return SIZE;
	}

	/**
	 * @see org.eclipse.draw2d.Figure#paintFigure(Graphics)
	 */
	protected void paintFigure(Graphics g) {
		test(g);
	}
	
	private void test(Graphics graphics){
		Rectangle bound = this.getBounds().getCopy();
		
		Point firstLeft = new Point(bound.x+5,bound.y+bound.height/2);
		Point firstRight = new Point(bound.x-5+bound.width,bound.y+bound.height/2);
		
		Point secondLeft = new Point(bound.x+bound.width/4,bound.y+bound.height*3/4-5);
		Point secondRight = new Point(bound.x+bound.width*3/4,bound.y+bound.height*3/4-5);
		
		
		Point thirdLeft = new Point(bound.x+bound.width/2-10,bound.y+bound.height-10);
		Point thirdRight = new Point(bound.x+bound.width/2+10, bound.y+bound.height-10);
		
		Point centerPoint = new Point(bound.x+bound.width/2,bound.y+bound.height/2);
		Point centerTopPoint = new Point(bound.x+bound.width/2,bound.y);
		
		graphics.setLineWidth(1);
		
		graphics.drawLine(firstLeft, firstRight);
		graphics.drawLine(secondLeft, secondRight);
		graphics.drawLine(thirdLeft, thirdRight);
		graphics.drawLine(centerPoint, centerTopPoint);
		
		 ((FixedConnectionAnchor)this.connectionAnchors.get(SimpleOutput.TERMINAL_OUT)).offsetH = bound.width/2;
		 ((FixedConnectionAnchor)this.connectionAnchors.get(SimpleOutput.TERMINAL_OUT)).offsetV = bound.height;
		 inputConnectionAnchors.addElement(this.connectionAnchors.get(SimpleOutput.TERMINAL_OUT));
		 
	}

}
